// pages/userinfo/index.js
const App = getApp();
const Config = require('../../config.js');
const Utils = require('../../static/js/utils.js');

import wxCharts from "../../static/js/wxcharts.js";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nickName: '', // 昵称
    avatarUrl: '', // 头像地址
    openid: '',
    userId: '', // 
    department: '', //
    level: 1, // 
    levelName: '', //
    levelImage: '', // 
    integral: 0, // 积分
    total: 0, // 总场次
    winTimes: 0, // 胜场
    winningRate: 0, // 胜率
    categories: [],
    seriesData: [],
    radarMaxValue: 0,
    shareTimes: 1000000, // 分享剩余次数
    shareClicked: true, // 是否点击了分享
    score1004: 0, // 
    score1005: 0, // 
    score1006: 0, // 
    score1007: 0, // 
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    
    let that = this;
    that.setData({
      openid: App.globalData.openid,
      nickName: App.globalData.qyName,
      avatarUrl: App.globalData.avatarUrl,
      integral: App.globalData.integral
    })
 
    Utils.ajax(Config.service.infoUrl, {
      data: {
        
          openid: App.globalData.openid
        
      }
    }, res => {
      if (res.code == 200) {
    
        that.setData({
          total: res.data.total,
          winTimes: res.data.win,
          winningRate: res.data.total > 0 ? (res.data.win / res.data.total * 100).toFixed(2) : 0,
          score1004: res.data.today,
          score1005: res.data.rank

        })
      }


    })
   
  },

  

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

 



  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    let that = this;
    that.setData({
      shareClicked: true
    })
    return {
      title: '把我分享给大家吧！',
      path: '/pages/home/index',
      imageUrl: '/static/images/share-pk.png',
      success: res => {

      }
    };
  }
})